package io.openmessaging;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class 回文串 {

    public static void main(String[] args) {
        String[] strList="aab".split("");;
        List<List<Integer>> result=new ArrayList<>();
        help(strList,1,result,new String(strList[0]));
        System.out.println(result);

    }
    public static void help(String[] nums, int idx,List result,String sb) {
        if(sb.length()>0&&isReturnArr(sb)){
            result.add(sb);
        }
        for (int i = idx; i < nums.length; i++) {
            sb=sb+nums[i];
            help(nums, i+1,result,sb);
            sb=sb.substring(0,sb.length()-1);
        }
    }

    private static boolean isReturnArr(String sb){
        for(int i=0;i< sb.length();i++){
            char start=sb.charAt(i);
            char end=sb.charAt(sb.length()-1-i);
            if(start!=end){
                return false;
            }
        }
        return  true;
    }

    }


